import { FC } from "react";
import { Button, Dropdown, message, Space } from "antd";
import { DownOutlined, FileWordOutlined, FilePdfOutlined } from '@ant-design/icons';
import type { MenuProps } from "antd";
import { httpPostDownload } from "@utils/HttpUtil";
import { getToday } from "@utils/TimeUtil";

const ToolbarExport: FC<any> = ({data})=>{

  const handleMenuClick: MenuProps["onClick"] = (e) => {
    if (e.key === "word") {
      if(data.length === 0){
        message.error("不可导出空试卷");
        return;
      }
      httpPostDownload("/fileRecord/exportWord", "测试文件.docx", {
        docTitle: getToday() + "习题",
        problemList: data,
      });
    }
  };
  
  const items: MenuProps["items"] = [
    {
      label: "导出PDF",
      key: "pdf",
      icon: <FilePdfOutlined />,
    },
    {
      label: "导出Word",
      key: "word",
      icon: <FileWordOutlined />,
    },
  ];
  
  const menuProps = {
    items,
    onClick: handleMenuClick,
  };

    return (
      <>
        <Dropdown menu={menuProps}>
          <Button type="primary" style={{ marginTop: 20, marginLeft: 20 }}>
            <Space>
              导出
              <DownOutlined />
            </Space>
          </Button>
        </Dropdown>
      </>
    );

}

export default ToolbarExport;